<?php
/**
 * User: day
 * Date: 2018/08/07
 * Time: 23:42
 */

namespace App\Services\ThirdAPI;

use Illuminate\Support\Facades\Log;
use common\enum\CommonEnum;

class EBETAPIService {
    protected $apiName  = 'EBET';

    const GAMENAME = [
        1 => '百家乐',
        2 => '龙/虎',
        3 => '骰宝',
        4 => '轮盘',
        5 => '水果机',
        6 => '试玩水果机',
        7 => '区块链百家乐'
    ];

    const betContent = [
        //百家乐：
        '60' => '闲',
        '66' => '闲对',
        '68' =>'和',
        '80' =>'庄',
        '88' => '庄对',
        '86' => '幸運六',
        '81' => '庄龙宝',
        '61' => '闲龙宝',
        '70' => '大',
        '71' => '小',
        '82' => '庄单',
        '83' => '庄双',
        '62' => '闲单',
        '63' => '闲双',
        //龙虎：
        '10' =>'龙',
        '11' =>'虎',
        //骰宝
        '100' =>'单',
        '101' =>'双',
        '102' =>'大',
        '103' =>'小',
        '104' => '对子1',
        '105' => '对子2',
        '106' => '对子3',
        '107' => '对子4',
        '108' => '对子5',
        '109' => '对子6',
        '110' => '围骰1',
        '111' => '围骰2',
        '112' => '围骰3',
        '113' => '围骰4',
        '114' => '围骰5',
        '115' => '围骰6',
        '116' => '全围',
        '117' => '4点',
        '118' => '5点',
        '119' => '6点',
        '120' => '7点',
        '121' => '8点',
        '125' => '9点',
        '126' => '10点',
        '127' => '11点',
        '128' => '12点',
        '129' => '13点',
        '130' => '14点',
        '131' => '15点',
        '132' => '16点',
        '133' => '17点',
        '134' => '单点数',
        '135' => '单点数2',
        '136' => '单点数3',
        '137' => '单点数4',
        '138' => '单点数5',
        '139' => '单点数6',
        '140' => '组合1-2',
        '141' => '组合1-3',
        '142' => '组合1-4',
        '143' => '组合1-5',
        '144' => '组合1-6',
        '145' => '组合2-3',
        '146' => '组合2-4',
        '147' => '组合2-5',
        '148' => '组合2-6',
        '149' => '组合3-4',
        '150' => '组合3-5',
        '151' => '组合3-6',
        '152' => '组合4-5',
        '153' => '组合4-6',
        '154' => '组合5-6',
        '155' => '二同号',
        '156' => '三不号',
        //轮盘
        '200' => '直接注',
        '201' => '分注',
        '202' => '街注',
        '203' => '角注',
        '204' => '三数',
        '205' => '四个号码',
        '206' => '线注',
        '207' => '列注',
        '208' => '打注',
        '209' => '红',
        '210' => '黑',
        '211' => '单',
        '212' => '双',
        '213' => '大',
        '214' => '小',
        //水果机/老虎机：null
    ];

    const ORIGIN = [
        -1 => CommonEnum::DEVICE_H5,//Other
        0 =>  CommonEnum::DEVICE_H5,//Android
        1 =>  CommonEnum::DEVICE_H5,//iOS
        2 => CommonEnum::DEVICE_H5,//Mobile H5
        3 => CommonEnum::DEVICE_PC//PC H5
    ];

    /**
     * 拉取第三方游戏SG的玩家注单数据
     * @param int $startTime 抓取时间段的开始时间
     * @param int $endTime 抓取时间段的结束时间
     * @return string|unknown
     */
    public function getEBETOrders($startTime, $endTime) {
        Log::info("EBET 获取注单：" . date("Y-m-d H:i:s", $startTime) . " - " . date("Y-m-d H:i:s", $endTime));
//        Log::info("EBET 获取注单：" . $startTime.' - '.$endTime);
        $url = config('app.rpcserver') . "/api/getOrders";
        $res = GameApiService::request($url, 'get', [
            'api_name' => 'EBET',
            'start_time' => $startTime,
            'end_time' => $endTime,
        ]);
        return $res;
    }

    public static function getBetConetnt($data){
        $betContent = $result = '';
        foreach($data['betMap'] as $v){
            if(isset(self::betContent[$v['betType']])){
                $content = self::betContent[$v['betType']];
                $content .= isset($v['betNumber']) ? implode(',', $v['betNumber']) : '';
                $content .= ':'.$v['betMoney'].';';
            }else{
                Log::error("EBET视讯拉取注单：找不到下注内容类型:".$data['betType']);
            }
            $betContent .= $content;
        }
        if($data['gameType'] == 1){//百家乐
            /*foreach ($data['judgeResult'] as $k => &$re){
                if(!isset(self::betContent[$re])){
                    qq($data);
                }
                $re = self::betContent[$re];
            }
            $result = implode(',', $data['judgeResult']);*/
            $result = '闲家总和点数:'.$data['playerResult'].',庄家总和点数:'.$data['bankerResult'];
        }
        if($data['gameType'] == 2){//龙虎
            $result = '龙:'.$data['dragonCard'].';虎:'.$data['tigerCard'];
        }
        if($data['gameType'] == 3){//骰宝
            $result = implode(',', $data['allDices']);
        }
        if($data['gameType'] == 4){//轮盘
            $result = $data['number'];
        }
        return $betContent.'结果:'.$result.';';
    }

}
